package cn.edu.ecut.service;

import cn.edu.ecut.dao.OptionDao;
import cn.edu.ecut.dao.TopicDao;
import cn.edu.ecut.entity.Option;
import cn.edu.ecut.entity.Topic;

import java.util.List;

public class TopicService {

    private TopicDao topicDao = new TopicDao();
    private OptionDao optionDao = new OptionDao();

    public List<Topic> loadTopics( int moduleId ){

        // 根据模块查询题目(仅查询题目，不包含题目下的选项)
        List<Topic> topics = topicDao.findByModule( moduleId );

        // 迭代List集合，为每个题目查询选项
        for( Topic t :topics ) {
            int topicId = t.getId() ;
            List<Option> options = optionDao.findByTopicId( topicId );
            t.setOptions( options );
        }

        return topics ;
    }

}
